import numpy as np

arr1 = np.array([1, 2, 3, 4])
print(arr1)
print(arr1.dtype)

arr2 = np.array([1.2, 2.3, 3.4, 4.5])
print(arr2)
print(arr2.dtype)

# 两个数组相加
print(arr1 + arr2)

# 数组所有元素+8
print(arr1 + 8)     # [ 9 10 11 12]
# 数组所有元素*3
print(arr2 * 3)     # [ 3.6  6.9 10.2 13.5]


# 定义二维数组，初始化为0
print(np.zeros((2, 3)))
# 定义二维数组，初始化为1
print(np.ones((3, 2)))
# 定义三维数组，初始化为空(会用随机数填充)
print(np.empty((2, 3, 4)))

# 切片
arr3 = np.arange(8)
print(arr3)         # [0 1 2 3 4 5 6 7]
arr3[5] = 88
arr3[6:8] = 99

arr_slice = arr3[0:6].copy()
print(arr3)         # [ 0  1  2  3  4 88 99 99]
print(arr_slice)    # [ 0  1  2  3  4 88]


